<?php
defined('_AppMiage') or die('Restricted access');
include_once (DS . 'include/header.php');
include_once (DS . 'include/menu.php');

$dates = array();

if (isEtudiant ())
{
    $dates = Date::getListByPromo($global_member->getIdPromo());
?>

    <div id="content">
    <?php
    if (!empty($dates))
    {
    ?><table><?php
        foreach ($dates as $date)
        {
    ?>
            <tr>
                <td><b><?php echo stripcslashes($date->TitreDate); ?></b></td>
                <td>
                <?php
                switch ($date->TypeDate)
                {
                    case 0:
                        echo ucwords(utf8_decode(strftime(DATE_FORMAT_FR, $date->ValeurDate)));
                        break;
                    case 1:
                        $timestamp = intval($date->ValeurDate);
                        $time = Tools::transformTimestampToDuree($timestamp);
                        $mois = $time['mois'];
                        $jours = $time['jours'];
                        echo "$mois mois";
                        if ($jours >= 14 && $jours <= 16)
                        {
                            echo " et demi";
                        }
                        elseif ($jours == 0)
                        {

                        }
                        else
                        {
                            echo " et $jours jours";
                        }
                        break;
                    case 2:
                        echo stripcslashes($date->ValeurDate);
                        break;
                }
                ?>
            </td>
        </tr>
        <?php
            }
        ?></table><?php
        }
        else
        {
            echo "Aucune date n'a &eacute;t&eacute; d&eacute;finit pour le moment.";
        }
        ?>
    </div>

<?php
    }
    else
    {
        $dates = Date::getListGroupByPromo();
?>

        <div id="content">
    <?php
        if (!empty($dates))
        {
            foreach ($dates as $idPromo => $datePromo)
            {
                $promo = new Promo($idPromo);
                echo '<h3><b>Pour les ' . stripcslashes($promo->getNom()) . ' :</b></h3>';
    ?>
                <table>
        <?php foreach ($datePromo as $date)
                { ?>
                    <tr>
                        <td>
                            <b>
                    <?php
                    echo stripcslashes($date->TitreDate);
                    ?>
                </b>
            </td>
            <td>
                <?php
                    switch ($date->TypeDate)
                    {
                        case 0:
                            echo ucwords(utf8_decode(strftime(DATE_FORMAT_FR, $date->ValeurDate)));
                            break;
                        case 1:
                            $timestamp = intval($date->ValeurDate);
                            $time = Tools::transformTimestampToDuree($timestamp);
                            $mois = $time['mois'];
                            $jours = $time['jours'];
                            echo "$mois mois";
                            if ($jours >= 14 && $jours <= 16)
                            {
                                echo " et demi";
                            }
                            elseif ($jours == 0)
                            {
                                
                            }
                            else
                            {
                                echo " et $jours jours";
                            }
                            break;
                        case 2:
                            echo stripcslashes($date->ValeurDate);
                            break;
                    }
                ?>
                </td>
            </tr>
<?php } ?>
            </table>
    <?php
            }
        }
        else
        {
            echo "Aucune date n'a &eacute;t&eacute; d&eacute;finit pour le moment.";
        }
        ?></div><?php
    }
    ?>

<?php
    include_once (DS . 'include/sidebar.php');
    include_once (DS . 'include/footer.php');
?>